<!DOCTYPE html>
<html>
  <head>
    <link href="ReswellStyling.css" rel="stylesheet" type="text/css"></link>
  </head>
  <body>

    <h1>The Developer Help System</h1>
    <strong>NOTE: Be sure to have java running within your browser when running the program.</strong>


    <h2>Requirements</h2>
    <ol>
      <li>Ubuntu 12.04 (32 bit) [This is what was used and recommended but is not essential]</li>
      <li>Python 2.7</li>
      <li>MySQL</li>
    </ol>

    <h2>How To Setup</h2>
    <ol>
      <li>$ cd /path/to/reswell/legocalendar</li>
      <li>A small script was made to install all the necessary modules:  $ ./setup_legocal.script</li>
      <li>See <strong>Database Schema</strong> below for setting up WELLGO tables.</li>
    </ol>

    <h2>Overview</h2>
    <p>WELLGO (and RESWELL, which is included as a separate page) runs on the Pyramid Framework. Their excellent documentation (http://docs.pylonsproject.org/projects/pyramid/en/latest/#) made for a nice introduction to python web development. The file structure here (Pyramid calls it a <strong>scaffold</strong>) was setup automatically by Pyramid. I will briefly walk through each directory:</p>
    <br>
    <p><strong>legocalendar/</strong> -  the top directory containing stuff like development.ini, production.ini, and various config files. The folder's contents rarely need to be modified.</p>
    <p><strong>legocalendar/legocalendar/</strong> -  this is where you start to see our code..  __init__.py contains the main entry point and maps URI's to specific functions. Rules.py contains the health rules used to analyze a user's calendar. Googe_calendar_export.py contains a function that exports a set of timeblocks to Google Calendar.</p>
    <p><strong>legocalendar/legocalendar/config/</strong> - contains config files for customizing Reswell. Developers should specify in dataSources.conf the info necessary to connect to a data source (host, port, username, password), and also the name of the field each data source will try to perform joins on. This file simply contains a JSON object, which is both human readable and easy to parse.</p>
    <p><strong>legocalendar/legocalendar/models/</strong> - contains classes representing database tables. __init__.py contains some SQLAlchemy setup code (including the local databases's host and password). Analysis.py and datas.py contain classes that map to the 'analysis' and 'datas' tables respectively.</p>
    <p><strong>legocalendar/legocalendar/models/reswell/</strong> - contains classes for the Reswell models. Reswell is described in more detail later. Each of these classes represent a datasource. FDB.py maintains a list of data source wrappers, dynamically generated from dataSources.conf.</p>
    <p><strong>legocalendar/legocalendar/static/</strong> - contains all static files that are viewable to the public (this can be changed in legocalendar/legocalendar/__init__.py. I put all CSS, JS, and JAR files in this directory.</p>
    <p><strong>legocalendar/legocalendar/reswell_gui/</strong> - contains Java code for the Reswell Java Applet.</p>
    <p><strong>legocalendar/legocalendar/views/</strong> - contains all the functions that serve Response objects back to the client.  Index.py contains all the views that WELLGO uses and Reswell.py contains functionality for the Reswell app.</p>
    <p><strong>legocaendar/legocalendar/views/templates/</strong> - contains template files that are served to the client. Pyramid uses Chameleon, a powerful python templating system. So far, reswell.pt is the only file that makes use of Chameleon's embedded python capabilities. It provides a JSON string representing the data source schemas as an argument to the Reswell Applet.</p>

    <h2>Database Schema</h2>
    <p>RESWELL does not use a database (though it integrates with others). WELLGO uses a MySQL database called <strong>legocalendar</strong>, which contains two tables called <strong>Analysis</strong> and <strong>Datas</strong>. The SQL statements to create these tables are:</p>
    <p>CREATE TABLE `analysis` (<br> 
      `cid` int(11) NOT NULL AUTO_INCREMENT,<br> 
      `uid` varchar(50) DEFAULT NULL, <br>
      `timestamp` bigint(20) DEFAULT NULL,<br> 
      `isreal` tinyint(1) DEFAULT NULL, <br>
      `drinking_rule` tinyint(1) DEFAULT NULL,<br> 
      `breakfast_rule` tinyint(1) DEFAULT NULL,<br> 
      `threeMeals_rule` tinyint(1) DEFAULT NULL, <br>
      `exercise_rule` tinyint(1) DEFAULT NULL, <br>
      `sevenHours_rule` tinyint(1) DEFAULT NULL, <br>
      `yoyoSleep_rule` tinyint(1) DEFAULT NULL, <br>
      `socializing_rule` tinyint(1) DEFAULT NULL, <br>
      `spiritual_rule` tinyint(1) DEFAULT NULL, <br>
      `study_rule` tinyint(1) DEFAULT NULL, <br>
      `work_rule` tinyint(1) DEFAULT NULL, <br>
      PRIMARY KEY (`cid`) <br>
      ); <br>
      <br>
      and<br>
      <br>
      CREATE TABLE `datas` (<br> 
      `cid` int(11) NOT NULL AUTO_INCREMENT,<br> 
      `uid` varchar(50) DEFAULT NULL, <br>
      `timestamp` bigint(20) DEFAULT NULL,<br> 
      `isreal` tinyint(1) DEFAULT NULL, <br>
      `iscomplete` tinyint(1) DEFAULT NULL, <br>
      `ttl_class` double DEFAULT NULL, <br>
      `ttl_drinking` double DEFAULT NULL, <br>
      `ttl_eating` double DEFAULT NULL, <br>
      `ttl_exercising` double DEFAULT NULL, <br>
      `ttl_misc` double DEFAULT NULL, <br>
      `ttl_sleeping` double DEFAULT NULL, <br>
      `ttl_socializing` double DEFAULT NULL, <br>
      `ttl_spiritual` double DEFAULT NULL, <br>
      `ttl_studying` double DEFAULT NULL, <br>
      `ttl_work` double DEFAULT NULL, <br>
      `avg_nightly_sleep_weekday` double, <br>
      `avg_nightly_sleep_weekend` double, <br>
      `days_drank` tinyint, <br>
      `avg_daily_meals` double, <br>
      `days_exercised` tinyint, <br>
      PRIMARY KEY (`cid`) <br>
      );</p>

    <h2>Reswell Overview</h2>
    <p>Reswell is my Senior Project and is considered an extension of WELLGO. Below is a high level overview of its design:</p>
    <p><img src="ReswellOverview.jpg" alt="Reswell Overview Image"></p>

    <ul>
      <li>The Admin is a human user interacting with the application.</li> 
      <li>The Java Applet is what the user primarily interacts with to add/drop fields and apply filters.</li> 
      <li>The Pyramid Framework directs each request to functions. In this case, we only use 3   views to handle all requests:</li>

      <ol>
	<li>/reswell returns the main page containing the Java Applet.</li>
	<li>/reswell/help returns a help page</li>
	<li>/reswell/apply_filters does not return a page, but instead returns a JSON string representing the new set of results</li>
      </ol>

      <li>Federated Database Engine (FDB) manages the data source integration. It parses   dataSources.conf and builds a list of data source wrappers.</li>
      <li>A Data Source Wrapper represents a single data source. They each contain a <strong>getSchema()</strong>  function and <strong>query()</strong> function. The FDB doesn't care how they implement these functions.  </li>
      <li>Later, Custom Wrappers may be necessary for sources where a schema can not be   dynamically generated (eg. NoSQL databases). Currently, Reswell does not integrate with such  sources, but it should be able to handle them when the time comes.</li>
    </ul>

    <h2>How The System Works</h2>
    <p>The user requests the <strong>/reswell</strong> page, which in turn asks the FDB for each data source's schema. The FDB asks each wrapper for his schema, and returns a single dictionary object. This dictionary becomes a JSON string and is inserted as an argument to the Java Applet. The Applet is then served to the user.<br>
      <br>
      The user applies filters to the fields. The request is sent to <strong>/reswell/apply_filters</strong>, which passes the filters along to the FDB. The FDB queries the appropriate wrappers and joins the results they send back. The FDB returns the results, which are served back the Applet.</p>

  </body>
</html>
